# 引入公共的模块
from MY_ECShop.common.base import create_browser, Base


# 创建一个注册类
class PageRegister(Base):
    # 定义属性
    url = "http://localhost:8080/ecshop/user.php?act=register"
    username = ('id', 'username')
    email = ('id', "email")
    password = ('id', 'password1')
    confirm_password = ('id', 'conform_password')
    qq = ('name', 'extend_field2')
    office_phone = ('name', 'extend_field3')
    home_phone = ('name', 'extend_field4')
    phone = ('name', 'extend_field5')
    prompt_questions = ('name', 'sel_question')
    question_answer = ('name', 'passwd_answer')
    select_agreement = ('name', 'agreement')
    register_click = ('name', 'Submit')
    is_success = ('class name', 'f4_b')

    # 定义方法
    def page_register_open_web(self):
        """
        打开注册网址,访问注册页面
        """
        self.base_open_web(self.url)

    def page_register_input_username(self, user_message):
        """
        输入注册用户名
        """
        self.base_input_massage(self.username, user_message)

    def page_register_input_email(self, user_email):
        """
        输入注册邮箱email
        """
        self.base_input_massage(self.email, user_email)

    def page_register_input_password(self, user_password):
        """
        输入注册密码
        """
        self.base_input_massage(self.password, user_password)

    def page_register_confirm_password(self, user_confirm):
        """
        输入注册确认密码
        """
        self.base_input_massage(self.confirm_password, user_confirm)

    def page_register_input_qq(self, user_qq):
        """
        输入注册QQ号码
        """
        self.base_input_massage(self.qq, user_qq)

    def page_register_office_phone(self, user_office):
        """
        输入注册办公电话
        """
        self.base_input_massage(self.office_phone, user_office)

    def page_register_home_phone(self, user_home):
        """
        输入注册家庭电话
        """
        self.base_input_massage(self.home_phone, user_home)

    def page_register_phone(self, user_phone):
        """
        输入注册手机
        """
        self.base_input_massage(self.phone, user_phone)

    def page_register_prompt_questions(self, number):
        """
        选择注册密码提示问题,通过索引号选择
        """
        self.base_drop_down_menu(self.prompt_questions, number)

    def page_register_question_answer(self, answer):
        """
        输入注册密码问题答案
        """
        self.base_input_massage(self.question_answer, answer)

    def page_register_select_agreement(self):
        """
        勾选注册"我已看过并接受协议"
        """
        self.base_checkbox(self.select_agreement)

    def page_register_click(self):
        """
        点击注册按钮
        """
        self.base_click(self.register_click)

    def page_register_is_success(self):
        """
        注册成功输出注册的用户名
        """
        result = self.base_get_text(self.is_success)
        return result

    def page_register_quit_web(self):
        """
        关闭谷歌浏览器
        """
        self.base_quit_web()


if __name__ == '__main__':
    # 遍历列表套字典,找出每个字典
    driver = create_browser()  # 创建一个浏览器对象
    rp = PageRegister(driver)  # 实际化一个Ecshop注册页面的对象
    rp.page_register_open_web()  # 进入注册页面
    rp.page_register_input_username("test1")  # 输入注册用户名
    rp.page_register_input_email("2992278814@qq.com")  # 输入注册邮箱
    rp.page_register_input_password("123456")  # 输入注册密码
    rp.page_register_confirm_password("123456")  # 输入注册确认密码
    rp.page_register_input_qq("234567892")  # 输入注册qq
    rp.page_register_office_phone("23456789")  # 输入注册办公室电话
    rp.page_register_home_phone("24689643")  # 输入注册家庭电话
    rp.page_register_phone("1365367890")  # 输入注册手机
    rp.page_register_prompt_questions(2)  # 输入注册密码提示问题-->索引号
    rp.page_register_question_answer("保密")  # 输入注册密码问题答案
    rp.page_register_select_agreement()  # 勾选注册"我已看过并接受协议"
    rp.page_register_click()  # 点击注册安钮
    my_result = rp.page_register_is_success()  # 输出注册成功的用户名
    rp.page_register_quit_web()  # 关闭谷歌浏览区
